#include<stdio.h>

#define LEN 10

int a[LEN]		= {1,2,3,3,4,5,6,6,7,8};
int searchTimes	= 0;

int
binarySearch( int number ) {
	int mid;
	int start	= 0;
	int end		= LEN - 1;
	searchTimes	= 0;
	while(start <= end) {
		mid		= (start + end ) / 2;
		searchTimes ++;
		if(number > a[mid]) {
			start = mid + 1;
		} else if(number < a[mid]) {
			end	= mid - 1;
		} else {
			return mid;
		}
	}
	
	return -1;
}

void printSearchTimes( void ) {
	printf("Search times is %d\n", searchTimes);
}

int
main(int * argc, char * argv[]) {
	int number	= 8;
	printf("The number %d location is %d\n", number,binarySearch(number));
	printSearchTimes();
	return 0;
}